# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=brunsli
pkgver=0.1
pkgrel=1
pkgdesc="Practical JPEG Repacker"
url="https://github.com/google/brunsli"
arch="all"
license="MIT"
makedepends="
	brotli-dev
	cmake
	samurai
	"
subpackages="$pkgname-libs $pkgname-dev"
source="brunsli-$pkgver.tar.gz::https://github.com/google/brunsli/archive/refs/tags/v$pkgver.tar.gz
	10-use_shared_libraries.patch
	20-soname.patch"

prepare() {
	default_prepare

	rm -rf third_party
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B out -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DVERSION=$pkgver \
		$CMAKE_CROSSOPTS
	cmake --build out
}

check() {
	out/cbrunsli 2>&1 | grep Usage
	out/dbrunsli 2>&1 | grep Usage
}

package() {
	DESTDIR="$pkgdir" cmake --install out
}

sha512sums="
a5967d183664bc055944e9391ea7394a24eb62f2fe3d654a8dfbe4874c65cec170258c74e56d9d32cab1783658554f3f4667bb5a8d605ed741fe9f93ee0abbcb  brunsli-0.1.tar.gz
670e0267a6b10231b6b0322c55e1c78322475e88c7a4d04761a3246ca91a461a185a56623de007a3c18eb70756de234237195bc5b07ffb7d41757a7f1fd030d5  10-use_shared_libraries.patch
c857cf3377a6c598334b6dff5b92c6590faa2cf34a5e37cd8b25113aef497408ae992c12a5c876141803be74ecf7d1fe7722d5c4a0c7558a3bf821146bd43c91  20-soname.patch
"
